﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XQ.WeChatOfficialAccount.DAL;
using XQ.WeChatOfficialAccount.DAL.DAL;
using XQ.WeChatOfficialAccount.DAL.Model;

namespace XQ.WeChatOfficialAccount.BLL.Sys
{
    public class DictCategoryBll
    {
        public List<Sys_DicCategory> GetDictCategoryList()
        {
            DictCategoryDal dal = new DictCategoryDal();
            return dal.GetDictCategoryList();
        }

        /// <summary>
        /// 根据ID获取字典类型
        /// </summary>
        /// <param name="dictCategoryId"></param>
        /// <returns></returns>
        public Sys_DicCategory GetDictCategoryById(int dictCategoryId)
        {
            DictCategoryDal dal = new DictCategoryDal();
            return dal.GetDictCategoryById(dictCategoryId);
        }

        /// <summary>
        /// 保存字典类型
        /// </summary>
        /// <param name="dicCategory"></param>
        /// <returns></returns>
        public bool SaveDictCategory(Sys_DicCategory dicCategory)
        {
            DictCategoryDal dal = new DictCategoryDal();
            if (dicCategory.ID == 0)
            {
                return dal.SaveDictCategory(dicCategory);
            }
            return dal.UpdateDictCategory(dicCategory);
        }

        public bool DeleteDictCategory(int dictCategoryId)
        {
            DictCategoryDal dal = new DictCategoryDal();
            return dal.DeleteDictCategory(dictCategoryId);
        }

        /// <summary>
        /// 批量删除字典类型
        /// </summary>
        /// <returns></returns>
        public bool DelDictCategorys(List<int> dictCategoryIds)
        {
            DictCategoryDal dal = new DictCategoryDal();
            return dal.DelDictCategorys(dictCategoryIds);
        }

        /// <summary>
        /// 获取字典类型的自动完成标签
        /// </summary>
        /// <returns></returns>
        public List<Tags> GetDictCategoryListForTags()
        {
            List<Tags> tagsList = new List<Tags>();
            DictCategoryDal dal = new DictCategoryDal();
            List<Sys_DicCategory> list =  dal.GetDictCategoryList();
            foreach (var sysDicCategory in list)
            {
                tagsList.Add(new Tags() { Label = sysDicCategory.Title, Value = sysDicCategory.Title});
            }

            return tagsList;
        }

        /// <summary>
        /// 检查是否有同名的
        /// </summary>
        /// <param name="categoryName"></param>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public bool IsHasSameName(string categoryName, int categoryId)
        {
            return new DictCategoryDal().IsHasSameName(categoryName, categoryId);
        }

        /// <summary>
        /// 检查是否有同名的
        /// </summary>
        /// <param name="categoryName"></param>
        /// <returns></returns>
        public bool IsHasSameName(string categoryName)
        {
            return IsHasSameName(categoryName, 0);
        }
    }
}
